package blt.app_core.api.invoce;

import java.util.List;

import blt.app_core.api.base.bean.OAuth;
import blt.app_core.api.base.bean.State;
import blt.app_core.api.base.callback.ComBack;
import blt.app_core.api.base.callback.StateCallback;
import blt.app_core.api.impl.BaseImpl;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by xgp on 2017/7/4.
 */

public class InvoiceImpl extends BaseImpl<InvoiceSerivce> implements InvoiceApi {


    @Override
    public void applyInvoice(String travelIds, String type,
                             String company, String billContent,
                             int amount, String specification, String email, String contactUser,
                             String contactPhone, String detailAddress) {

        mService.applyInvoice(0, travelIds, type, company, amount,
                specification, contactUser, detailAddress, contactPhone, email).enqueue(new Callback<State>() {
            @Override
            public void onResponse(Call<State> call, Response<State> response) {
                        notifyClients(InvoiceApi.class,InvoiceApi.onApplySuccess);
            }

            @Override
            public void onFailure(Call<State> call, Throwable t) {

            }
        });
    }

    @Override
    public void modifyInvoice(String travelIds, String type,
                              String company, String billContent,
                              int amount, String specification, String email, String contactUser,
                              String contactPhone, String detailAddress) {
        mService.updateInvoice(0, travelIds, type, company, amount,
                specification, contactUser, detailAddress, contactPhone, email).enqueue(new Callback<State>() {
            @Override
            public void onResponse(Call<State> call, Response<State> response) {

            }

            @Override
            public void onFailure(Call<State> call, Throwable t) {

            }
        });


    }

    @Override
    public void getInvoiceInfo(int page, int size) {
        mService.getInvoice(page, size).enqueue(new ComBack<InvoiceVo>() {
            @Override
            protected void onSuccess(List<InvoiceVo> data) {
                notifyClients(InvoiceApi.class, InvoiceApi.onInvoiceList, data);
            }
        });

    }

    @Override
    public void getInvoiceDetail(int id) {
        mService.getInvoiceDetail(id).enqueue(new StateCallback<InvoiceVo>() {
            @Override
            protected void onSuccess(InvoiceVo data) {
              notifyClients(InvoiceApi.class,InvoiceApi.onInvoiceDetail,data);
            }
        });

    }
}
